package com.kingdee.eas.fdc.contract.client;

import com.kingdee.bos.ctrl.kdf.data.event.RequestRowSetEvent;
import com.kingdee.bos.ctrl.kdf.table.event.KDTMouseEvent;
import com.kingdee.bos.ctrl.kdf.table.event.KDTSelectEvent;
import com.kingdee.bos.ui.face.CoreUIObject;
import com.kingdee.eas.base.commonquery.client.CommonQueryDialog;
import com.kingdee.eas.base.commonquery.client.CustomerQueryPanel;
import com.kingdee.eas.basedata.org.OrgType;
import com.kingdee.eas.common.client.UIFactoryName;
import com.kingdee.eas.fdc.basedata.FDCBillInfo;
import com.kingdee.eas.fdc.basedata.client.FDCClientHelper;
import com.kingdee.eas.fdc.basedata.client.FDCClientUtils;
import com.kingdee.eas.fdc.contract.ContractFacadeFactory;
import com.kingdee.eas.fdc.finance.DeductBillFactory;
import com.kingdee.eas.framework.ICoreBase;
import com.kingdee.jdbc.rowset.IRowSet;
import java.awt.event.ActionEvent;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;

public class DeductBillFullListUICTEx extends DeductBillFullListUI {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3035295479529523570L;

	public DeductBillFullListUICTEx() throws Exception {
		filterUI = null;
		commonQueryDialog = null;
	}

	public void storeFields() {
		super.storeFields();
	}

	public void onLoad() throws Exception {
		FDCClientUtils.checkCurrentCostCenterOrg(this);
		tblMain.checkParsed();
		super.onLoad();
		actionAddNew.setEnabled(false);
		actionEdit.setEnabled(false);
		actionRemove.setEnabled(false);
		actionLocate.setEnabled(false);
		actionCreateTo.setEnabled(false);
		actionTraceDown.setEnabled(false);
		actionTraceUp.setEnabled(false);
		actionCopyTo.setEnabled(false);
		actionAuditResult.setEnabled(false);
		actionMultiapprove.setEnabled(false);
		actionNextPerson.setEnabled(false);
		actionAddNew.setVisible(false);
		actionEdit.setVisible(false);
		actionRemove.setVisible(false);
		actionLocate.setVisible(false);
		actionCreateTo.setVisible(false);
		actionTraceDown.setVisible(false);
		actionTraceUp.setVisible(false);
		actionCopyTo.setVisible(false);
		actionAuditResult.setVisible(false);
		actionMultiapprove.setVisible(false);
		actionNextPerson.setVisible(false);
		menuBiz.setVisible(false);
		menuBar.remove(menuBiz);
		menuEdit.setVisible(false);
		FDCClientHelper.initTable(tblMain);
	}

	private CustomerQueryPanel getFilterUI() {
		if (filterUI == null)
			try {
				filterUI = new DeductBillFullFilterUI(this, actionOnLoad);
			} catch (Exception e) {
				handUIExceptionAndAbort(e);
			}
		return filterUI;
	}

	protected CommonQueryDialog initCommonQueryDialog() {
		if (commonQueryDialog != null) {
			return commonQueryDialog;
		} else {
			commonQueryDialog = super.initCommonQueryDialog();
			commonQueryDialog.setWidth(400);
			commonQueryDialog.addUserPanel(getFilterUI());
			return commonQueryDialog;
		}
	}

	protected boolean isShowAttachmentAction() {
		return false;
	}

	protected boolean initDefaultFilter() {
		return true;
	}

	protected boolean isIgnoreCUFilter() {
		return true;
	}

	protected OrgType getMainBizOrgType() {
		return OrgType.CostCenter;
	}

	protected boolean isFootVisible() {
		return true;
	}

	protected String getEditUIModal() {
		return UIFactoryName.NEWTAB;
	}

	protected void tblMain_tableClicked(KDTMouseEvent e) throws Exception {
		super.tblMain_tableClicked(e);
	}

	protected void tblMain_tableSelectChanged(KDTSelectEvent e)
			throws Exception {
		super.tblMain_tableSelectChanged(e);
	}

	public void actionView_actionPerformed(ActionEvent e) throws Exception {
		super.actionView_actionPerformed(e);
	}

	public void actionRemove_actionPerformed(ActionEvent actionevent)
			throws Exception {
	}

	public void actionRefresh_actionPerformed(ActionEvent e) throws Exception {
		super.actionRefresh_actionPerformed(e);
	}

	public void actionPrint_actionPerformed(ActionEvent e) throws Exception {
		super.actionPrint_actionPerformed(e);
	}

	public void actionQuery_actionPerformed(ActionEvent e) throws Exception {
		super.actionQuery_actionPerformed(e);
	}

	protected String getEditUIName() {
		return com.kingdee.eas.fdc.finance.client.DeductBillEditUI.class
				.getName();
	}

	protected ICoreBase getBizInterface() throws Exception {
		return DeductBillFactory.getRemoteInstance();
	}

	protected void execQuery() {
		super.execQuery();
		FDCClientUtils.fmtFootNumber(tblMain,
				new String[] { "entrys.deductAmt" });
		FDCClientHelper.initTable(tblMain);
	}

	public String[] getMergeColumnKeys() {
		String columnKeys[] = { "id", "state", "number" };
		return columnKeys;
	}

	private void setMergeColumn(boolean merge) {
		String mergeColumnKeys[] = getMergeColumnKeys();
		if (mergeColumnKeys != null && mergeColumnKeys.length > 0) {
			tblMain.checkParsed();
			tblMain.getGroupManager().setGroup(merge);
			for (int i = 0; i < mergeColumnKeys.length; i++) {
				tblMain.getColumn(mergeColumnKeys[i]).setGroup(merge);
				tblMain.getColumn(mergeColumnKeys[i]).setMergeable(merge);
			}

		}
	}

	protected void tblMain_doRequestRowSet(RequestRowSetEvent e) {
		setMergeColumn(true);
		super.tblMain_doRequestRowSet(e);
	}

	public void onGetRowSet(IRowSet rowSet) {
		super.onGetRowSet(rowSet);
		Map numberMap = new HashMap();
		try {
			rowSet.beforeFirst();
			do {
				if (!rowSet.next())
					break;
				String id = rowSet.getString("entrys.contractId");
				if (id != null)
					numberMap.put(id, id);
			} while (true);
			Map contractMap = ContractFacadeFactory.getRemoteInstance()
					.getContractNumberAndNameMap(numberMap);
			rowSet.beforeFirst();
			do {
				if (!rowSet.next())
					break;
				String id = rowSet.getString("entrys.contractId");
				if (id != null) {
					FDCBillInfo billInfo = (FDCBillInfo) contractMap.get(id);
					if (billInfo != null) {
						rowSet.updateString("entrys.contractNumber", billInfo
								.getNumber());
						rowSet.updateString("entrys.contractName", billInfo
								.getName());
					}
				}
			} while (true);
			rowSet.beforeFirst();
		} catch (Exception e) {
			handUIExceptionAndAbort(e);
		}
	}

	private static final Logger logger = CoreUIObject
			.getLogger(com.kingdee.eas.fdc.contract.client.DeductBillFullListUI.class);
	private CustomerQueryPanel filterUI;
	private CommonQueryDialog commonQueryDialog;
	private static final String ENTRYS_CONTRACT_NAME = "entrys.contractName";
	private static final String ENTRYS_CONTRACT_NUMBER = "entrys.contractNumber";
	private static final String CONTRACT_ID = "entrys.contractId";

}
